#include "GameRender.h"


CGameRender::CGameRender(HWND hWND)
{
	m_hWnd = hWND;
	m_hDC = ::GetDC(m_hWnd);
	m_memDC = ::CreateCompatibleDC(m_hDC);

	HBITMAP tempBMP = CreateCompatibleBitmap(m_hDC,g_screenWidth,g_screenHeight);
	SelectObject(m_memDC,tempBMP);
	init();
}

CGameRender::~CGameRender()
{
}

void CGameRender::init()
{
	m_pMapReader = MapReader::GetMapDataInstance();
}

void CGameRender::render(float timeDelta)
{
	drawBackground();

	drawScene();

	//sprintf(m_textoutBuffer, "FPS :  %d", renderFPS);
	sprintf_s(m_textoutBuffer, sizeof(m_textoutBuffer), "FPS :  %d" ,g_renderFPS);
	SetTextColor(m_memDC,RGB(242,167,5));
	TextOut (
		m_memDC, 
		static_cast<int >(g_screenWidth * 0.5f), 
		static_cast<int >(g_screenHeight * 0.5f),
		m_textoutBuffer, 
		strlen(m_textoutBuffer));

	BitBlt(m_hDC ,0, 0, g_screenWidth, g_screenHeight,m_memDC, 0, 0,SRCCOPY);
}



void CGameRender::drawBackground()
{
	//gray back ground
	HBRUSH hbrush1 = CreateSolidBrush(RGB(192, 192, 192));
	HPEN hpen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
	RECT screenRect;
	SetRect(&screenRect, 0, 0 ,g_screenWidth, g_screenHeight);
	FillRect(m_memDC, &screenRect, hbrush1);
	//draw blocks
	SelectObject(m_memDC, hpen);
	for(int i = 0; i < g_numCellRow; ++i)
	{
		MoveToEx(m_memDC, 0, i * g_cellSpace, NULL);
		LineTo(m_memDC, g_screenWidth, i * g_cellSpace);
	}
	for(int i = 0; i < g_numCellCol; ++i)
	{
		MoveToEx(m_memDC, i * g_cellSpace, 0,NULL);
		LineTo(m_memDC, i * g_cellSpace, g_screenHeight);
	}
	DeleteObject(hpen);
	DeleteObject(hbrush1);
}



void CGameRender::drawScene()
{

}
